﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using BOMS.DBUtility;//请先添加引用
using MySql.Data.MySqlClient;
namespace BOMS.DAL
{
    /// <summary>
    /// 数据访问类WarningDealwith。
    /// </summary>
    public class WarningDealwith
    {
        public WarningDealwith()
        { }
        #region  成员方法      

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(BOMS.Model.WarningDealwith model)
        {
            object obj = new object();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("BEGIN TRANSACTION;");
            strSql.Append("BEGIN TRY;");
            strSql.Append("update dbo.S_Warning set IsActive=0 where ID=@WarningID; insert into WarningDealwith(");
            strSql.Append("WarningID,Operator,OperateDescr,CreateTime,CreatorID)");
            strSql.Append(" values (");
            strSql.Append("@WarningID,@Operator,@OperateDescr,@CreateTime,@CreatorID)");
            strSql.Append(";select @@IDENTITY;");
            strSql.Append("END TRY BEGIN CATCH IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;");
            strSql.Append(" END CATCH;IF @@TRANCOUNT>0 COMMIT TRANSACTION;");
            if (DbHelper.DBType == "MsSql")
            {
                SqlParameter[] parameters = {
					new SqlParameter("@WarningID", SqlDbType.Int,4),
					new SqlParameter("@Operator", SqlDbType.NVarChar,50),
					new SqlParameter("@OperateDescr", SqlDbType.NVarChar,2000),
					new SqlParameter("@CreateTime", SqlDbType.DateTime),
					new SqlParameter("@CreatorID", SqlDbType.Int,4)};
                parameters[0].Value = model.WarningID;
                parameters[1].Value = model.Operator;
                parameters[2].Value = model.OperateDescr;
                parameters[3].Value = model.CreateTime;
                parameters[4].Value = model.CreatorID;

                 obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            }
            else if (DbHelper.DBType == "MySql")
            {
                MySqlParameter[] parameters = {
					new MySqlParameter("@WarningID", MySqlDbType.Int32,4),
					new MySqlParameter("@Operator", MySqlDbType.VarChar,50),
					new MySqlParameter("@OperateDescr", MySqlDbType.VarChar,2000),
					new MySqlParameter("@CreateTime", MySqlDbType.DateTime),
					new MySqlParameter("@CreatorID", MySqlDbType.Int32,4)};
                parameters[0].Value = model.WarningID;
                parameters[1].Value = model.Operator;
                parameters[2].Value = model.OperateDescr;
                parameters[3].Value = model.CreateTime;
                parameters[4].Value = model.CreatorID;

                obj = DbHelperMySql.GetSingle(strSql.ToString(), parameters);
            }
            if (obj == null)
            {
                return 1;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
       

       

       
        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "WarningDealwith";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法
    }
}

